import {Tools} from 'weaver-mobile';
import * as pageTypes from "../constants/OdocPageType";

const getLabel = Tools.getLabel;

const odocNavTitles = {
    [`${pageTypes.ODOC_TRANSFER_DIALOG}`]: getLabel('518550', '公文流转'),
    [`${pageTypes.ODOC_TRANSFER_DIALOG}/odoc_select_list`]: getLabel('512917', '选择常用去向'),
    [`${pageTypes.ODOC_TRANSFER_DIALOG}`]: getLabel('518550', '公文流转'),
    [`${pageTypes.ODOC_WITHDRAW_DIALOG}`]: getLabel(32025, "撤回"),
    [`${pageTypes.ODOC_WITHDRAW_MANAGER_DIALOG}`]: getLabel(32025, "撤回"),
    [`${pageTypes.ODOC_UPDATEOPERATOR_DIALOG}`]: getLabel(130106, "加减签"),
    [`${pageTypes.ODOC_CHANGE_ODOC_TYPE_DIALOG}`]: "",      //文种变更
    [`${pageTypes.ODOC_CHANGE_ODOC_CUS_TAB}`]: "",      //签字意见分组
    [`${pageTypes.ODOC_APPEND_SIGNLOG}`]: getLabel(520456, "代录意见"),
    [`${pageTypes.ODOC_APPEND_SIGNLOG_SELF}`]: getLabel(519035, "追加意见"),
    [`${pageTypes.ODOC_UPDATE_SIGNLOG}`]: getLabel(132410, "修改意见"),
    [`${pageTypes.ODOC_ADJUST_LOG}`]: getLabel(25990, "调整日志"),
    [`${pageTypes.ODOC_SIGN_APPROVAL}`]: "",     //签批
    [`${pageTypes.ODOC_SIGN_APPROVAL_HISTORY}`]: "",        //签批历史
};

export const checkJsApi = method => {
    return window.em && window.em.checkJsApi && window.em.checkJsApi(method);
}

export const setOdocNavTitle = (title, pathName = "") => {
    let navTitle = "";
    if (pathName) {
        if (pathName.indexOf("/req/odocComs") != -1) {
            pathName = pathName.replace("/req/odocComs/", "");
        }
        pathName = pathName;
        navTitle = odocNavTitles[pathName];
    }

    if (navTitle) {
        title = navTitle;
    }

    if (title) {
        document.title = title;
        if (checkJsApi("configNavigation")) {
            const nav = {
                'success': function (argument) {
                    console.log('setOdocNavTitle success', JSON.stringify(argument));
                },
                'fail': function (argument) {
                    console.log('setOdocNavTitle fail', JSON.stringify(argument));
                },
                'left': {},
                'right': {},
                'title': title,
                "showCloseButton": false
            };

            window.em && window.em.ready(function () {
                window.em.configNavigation({...nav});
            });
        }
    }
}